package com.nebula.api.modules.product.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nebula.api.modules.product.entity.ShopProduct;
import com.nebula.api.modules.product.mapper.ShopProductMapper;
import com.nebula.api.modules.product.service.IShopProductService;
import com.nebula.api.modules.product.vo.ProductVo;
import com.nebula.api.modules.product.vo.ShopProductVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 商品(单个商品,有库存量,例如iphone10,内存是256G,尺寸是9.6寸) 服务实现类
 * </p>
 *
 * @author my
 * @since 2022-09-17
 */
@Service
public class ShopProductServiceImpl extends ServiceImpl<ShopProductMapper, ShopProduct> implements IShopProductService {


    @Autowired
    private ShopProductMapper shopProductMapper;

    @Override
    public ProductVo selectProduct(Integer type, String name) {
//        调用mapper层方法
        List<ShopProductVo> shopProductVos = shopProductMapper.selectProduct(type);

//        封装参数
//        创建ProductVo对象
        ProductVo productVo = new ProductVo();
        productVo.setName(name);

//        设置data之前，再封装一个records
        HashMap<Object, Object> shopProductHashMap = new HashMap<>();
//        给shopProductHashMap设置一个key:records，他的值为shopProductVos
        shopProductHashMap.put("records", shopProductVos);
        productVo.setData(shopProductHashMap);

//        设置more
//        判断
        if (type == 1) {
//            精品
            productVo.setMore(productVo.getMore() + "1");
        } else {
//            热门
            productVo.setMore(productVo.getMore() + "2");
        }
//        返回ProductVo对象
        return productVo;
    }
}


//项目架构了解
//redis了解
//处理登录请求
//处理获取用户信息请求
//处理首页数据请求
